package com.fdm.controller.bankcommand;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

import com.fdm.controller._DisplayManager;
import com.fdm.model.BankAccountOutputVO;
import com.fdm.model._BankManager;
import com.fdm.model.exceptions.BankManagerException;

public class CloseAccountCommand implements _BankManagerCommand
{
	private _BankManager bankManager;
	private HttpServletRequest request;
	private _DisplayManager displayManager;
	private String message;

	@Override
	public void setBankManager(_BankManager bankManager) {
		this.bankManager=bankManager;
	}

	@Override
	public void setHttpServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	@Override
	public void setDisplayManager(_DisplayManager displayManager) {
		this.displayManager = displayManager;
	}

	@Override
	public void execute() throws BankManagerException, 
			ServletException, IOException {
		String accountNumber = request.getParameter("accountNumber");
		BankAccountOutputVO output = 
			bankManager.closeAcount(accountNumber);
		request.setAttribute("title", "Result of Operation");
		request.setAttribute("message", new Date()+ message+accountNumber);
		displayManager.setHttpServletRequest(request);
		displayManager.setResultJSP("/message.jsp");
		displayManager.displayOutput(output);
	}

	@Override
	public void setAttributes(_BankManager bankManager,
			HttpServletRequest request, _DisplayManager displayManager,
			String message) {
		this.setBankManager(bankManager);
		this.setDisplayManager(displayManager);
		this.setHttpServletRequest(request);
		this.setMessage(message);
	}

	@Override
	public void setMessage(String message) {
		this.message = message;
	}
}
